# Adogs
# 时间: 2021/8/3 13:49
import enum

import pygame


class TaskStatus(enum.IntEnum):
    """
    任务状态类
    用于表示当前任务的进行状态
    """
    start_dialog = 0
    do_task = 1
    win_dialog = 2
    fail_dialog = 3
    win_over = 4
    fail_over = 5


class BaseTask:
    """
    基本任务类
    方法:
    1.__init__(start_dialog, win_dialog, fail_dialog)
    2.do_task(key_down, key_list)
    3.do_self_task(key_down, key_list)
    4.get_status()
    5.draw(surface, view_x, view_y)
    6.draw_task(surface, view_x, view_y)
    """
    def __init__(self, start_dialog, win_dialog, fail_dialog):
        """
        初始化函数
        :param start_dialog: 任务开始对话
        :param win_dialog: 任务成功对话
        :param fail_dialog: 任务失败对话
        """

        self.start_dialog = start_dialog
        self.win_dialog = win_dialog
        self.fail_dialog = fail_dialog

        self.task_status = TaskStatus.start_dialog      # 设置任务状态

    def do_task(self, key_down, key_list):
        """
        任务状态切换函数
        :param key_down: 判断是否点击按键
        :param key_list: 判断是否有键被按下
        :return: 无返回值
        """
        if key_down and key_list[pygame.K_SPACE]:

            if self.task_status == TaskStatus.start_dialog:
                self.start_dialog.next_text()
                if self.start_dialog.is_finish():
                    self.task_status = TaskStatus.do_task

            if self.task_status == TaskStatus.win_dialog:
                self.win_dialog.next_text()
                if self.win_dialog.is_finish():
                    self.task_status = TaskStatus.win_over

            if self.task_status == TaskStatus.fail_dialog:
                self.fail_dialog.next_text()
                if self.fail_dialog.is_finish():
                    self.task_status = TaskStatus.fail_over

        if self.task_status == TaskStatus.do_task:
            self.do_self_task(key_down, key_list)

    def do_self_task(self, key_down, key_list):
        """
        每个任务进行时需要的函数
        这里交给派生类重写方法
        :param key_down: 判断是否点击按键
        :param key_list: 判断是否有键被按下
        :return: 无返回值
        """
        pass

    def get_status(self):
        """
        获取当前任务的状态
        :return: 任务状态
        """
        return self.task_status

    def draw(self, surface, view_x, view_y):
        """
        任务对话绘制函数
        :param surface: 绘制屏幕
        :param view_x: 屏幕相对x坐标
        :param view_y: 屏幕相对y坐标
        :return: 无返回值
        """
        if self.task_status == TaskStatus.win_over or self.task_status == TaskStatus.fail_over:
            return
        elif self.task_status == TaskStatus.start_dialog:
            self.start_dialog.draw(surface)
        elif self.task_status == TaskStatus.win_dialog:
            self.win_dialog.draw(surface)
        elif self.task_status == TaskStatus.fail_dialog:
            self.fail_dialog.draw(surface)
        self.draw_task(surface, view_x, view_y)

    def draw_task(self, surface, view_x, view_y):
        """
        任务具体绘制函数
        派生类重新写方法
        :param surface: 绘制屏幕
        :param view_x: 屏幕相对x坐标
        :param view_y: 屏幕相对y坐标
        :return: 无返回值
        """
        pass
